
import scipy.stats as stats
import pandas as pd
from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker
import seaborn as sns
# import matplotlib
import matplotlib.pyplot as plt
from matplotlib import rcParams
import numpy as np
import matplotlib.dates as mdates

# plt.use('Qt5Agg')


data=pd.read_csv('E:\江苏移动-hzy工作资料\\5GC学习资料\\01-中兴5GC资料\python-tasks\show interface brief.csv')

df = data.loc[:, ['run_time', 'BW(Mbps)']]
df.columns = ['time', 'data']

df['data']=df['data']+range(0,len(df['data']))
start_date = pd.to_datetime('2022-01-01 01:00:00')
end_date = pd.to_datetime('2022-12-31')

# date_list = pd.date_range(start_date, end_date, freq='D').strftime('%Y-%m-%d').tolist()
date_list = pd.date_range(start=start_date, periods=len(df), freq='Min').strftime('%Y-%m-%d %H:%M:%S').tolist()
df['time']=pd.to_datetime(date_list)

############################################################################################


############################################################################################
plt.style.use('seaborn-bright')
rcParams['font.sans-serif'] = ['SimHei']  # 中文为宋体
rcParams['font.serif'] = ['Times New Roman']  # 英文为新罗马
rcParams['axes.unicode_minus'] = False  # 正常显示负号
rcParams['font.size'] = 15  # 设置字号
# fig = plt.figure(figsize=(8, 6), dpi=80)
# grid = plt.GridSpec(4, 4, hspace=0.5, wspace=0.2)#调整子图之间的间距


fig=plt.figure(figsize=(8, 6), dpi=500,constrained_layout=True)  # 可以自动调整图表之间的距离大小
spec=plt.GridSpec(4,4,figure=fig)


ax_main = fig.add_subplot(spec[:, :-1])
ax_right = fig.add_subplot(spec[:, -1], xticklabels=[], yticklabels=[])#设置x轴和y轴刻度数据为空


# colors1='#00CED1'#点的颜色，即c的值，也可直接写为'b'、'r'
# colors2='#DC143C'
# colors = np.random.rand(9)

# # area=np.pi*4**2 #可设为s的大小，点的面积；可根据y值的大小来设置面积
# area1=np.pi*df['data'] ** 2  #可根据y值的大小来设置面积

ax_main.scatter(df['time'],df['data'], alpha=.9, marker='o',s=12, c='b',label='数据集1')

# ax_main.scatter(df['time'],df['data'], alpha=.9, marker='o',s=5, c='r',label='数据集2')
#’o’（圆形）、‘s’（正方形）、‘^’（三角形上标）

ax_main.legend(prop={'size': 12})
ax_main.set_xlabel('时间',fontweight='bold',fontsize=14) # 设置横纵轴label,加粗
ax_main.set_ylabel('流量(Mbps)',fontweight='bold',fontsize=14)

# 设置主刻度格式
hoursLoc = mdates.HourLocator(interval=1)  # 为1小时为1主刻度
ax_main.xaxis.set_major_locator(hoursLoc)
ax_main.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M\n%Y-%m-%d'))

# 设置副刻度格式
# minute =  mdates.MinuteLocator(interval=10)
minute = mdates.MinuteLocator(byminute=[0, 10, 20, 30, 40, 50])

ax_main.xaxis.set_minor_locator(minute) # 设置x轴刻度，每10分钟显示一个
ax_main.xaxis.set_minor_formatter(mdates.DateFormatter('%H:%M'))


# plt.setp(ax_main.xaxis.get_majorticklabels(), rotation=90)
# 设置主刻度旋转角度和刻度label刻度间的距离pad
ax_main.tick_params(which='major', axis='x', length=5, pad=4, direction='in',labelsize=11)
ax_main.tick_params(which='minor', axis='x', direction='in', labelsize=10.5)
ax_main.tick_params(axis='y', direction='in', labelsize=12)

ax_main.xaxis.grid(True, which='major',linestyle='--',linewidth=0.5,color='gray',zorder=0)#zorder=0标识置于底层
ax_main.xaxis.grid(True, which='minor',linestyle='--',linewidth=0.5,color='gray',zorder=0)#zorder=0标识置于底层
ax_main.yaxis.grid(True, which='major',linestyle='--',linewidth=0.5,color='gray',zorder=0)#zorder=0标识置于底层

#######################################################################################
######绘制副图--箱线图
sns.boxplot(df.data, ax=ax_right, orient="v")
ax_right.set_ylabel('',fontweight='bold',fontsize=14)
ax_right.set_xlabel('箱线图')

plt.show()


#
# #设置主刻度
# day =  mdates.DayLocator(interval=1)
# ax_main.xaxis.set_major_locator(day)
# ax_main.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
#
# # 设置副刻度格式
# hoursLoc = mdates.HourLocator(interval=8)  # 为20小时为1副刻度
# minute = mdates.HourLocator(byhour=[0, 10, 20])

# ax_main.xaxis.set_minor_locator(hoursLoc)
# ax_main.xaxis.set_minor_formatter(mdates.DateFormatter('%H'))
#
# # # 设置主刻度旋转角度和刻度label刻度间的距离pad
# ax_main.tick_params(which='major', axis='x', length=5, pad=20, direction='in')
# ax_main.tick_params(which='minor', axis='x', direction='in', labelsize=9)
# #
# dates1=pd.date_range(np.min(df['time']), np.max(df['time']),freq='1D')
# dates2=pd.date_range(np.min(df['time']), np.max(df['time']),freq='6H')
# plt.xticks(dates1,fontproperties='Times New Roman', size=12, weight='bold')
# plt.yticks(dates2,fontproperties='Times New Roman', size=12, weight='bold')
#
#




